package com.ct.gd.passport.view.policy;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.ct.gd.passport.R;
import com.ct.gd.passport.common.BaseActivity;
import com.ct.gd.passport.common.constants.UmengVar;
import com.ct.gd.passport.view.widget.CustomHeaderFragment;
import com.umeng.analytics.MobclickAgent;
import com.up91.common.android.helper.ToastHelper;

public class PolicySearchActivity extends BaseActivity implements OnClickListener {
	private FragmentManager				mFgMan;
	private CustomHeaderFragment		mFgHeader;
	private PolicyCatalogSearchFragment	mFgPolicyCatalogSearch;

	private EditText					mEdKeyword;

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.policy_search);
	}

	@Override
	protected void initViews() {
		mFgMan = getSupportFragmentManager();

		mFgHeader = (CustomHeaderFragment) mFgMan.findFragmentById(R.id.policy_header);
		mEdKeyword = (EditText) getLayoutInflater().inflate(R.layout.policy_search_input, null);
		mFgHeader.setCenterView(mEdKeyword);
		mFgHeader.setRightText(R.string.policy_search);
		mFgHeader.setRightOnClickListener(this);

		mFgPolicyCatalogSearch = (PolicyCatalogSearchFragment) mFgMan.findFragmentById(R.id.area_policy_catalog);
	}

	@Override
	public void onClick(View v) {
		MobclickAgent.onEvent(this, UmengVar.POLICY_SEARCH_SEND);
		String keyword = mEdKeyword.getText().toString().trim();
		if (TextUtils.isEmpty(keyword)) ToastHelper.toast(this, R.string.policy_search_input_hint);
		else mFgPolicyCatalogSearch.search(keyword);
	}

}
